package com.suarte.core;

import com.suarte.utils.Persistent;
import org.appfuse.model.BaseObject;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 * @date   Dec 8, 2010
 * @author Ggutierrez
 */
@Entity @Table(name="sa_contacts")
public class Contact extends BaseObject implements Persistent {
    private Long id;
    private String firstName;
    private String lastName;
    private String title;
    private String position;
    private String phone;
    private String movil;
    private String email;
    private Company company;
    private Long oldId;

    public Contact() {
    }

    @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="CONTACT_SEQ")
    @SequenceGenerator(name="CONTACT_SEQ",sequenceName="CONTACT_SEQ",allocationSize=1)
    public Long getId() {
        return id;
    }

    @Column(name="first_name", length=100)
    public String getFirstName() {
        return firstName;
    }

    @Column(name="last_name", length=100)
    public String getLastName() {
        return lastName;
    }

    @Column(name="title", length=100)
    public String getTitle() {
        return title;
    }

    @Column(name="position", length=100)
    public String getPosition() {
        return position;
    }

    @Column(name="phone", length=100)
    public String getPhone() {
        return phone;
    }

    @Column(name="movil", length=100)
    public String getMovil() {
        return movil;
    }

    @Column(name="email", length=100)
    public String getEmail() {
        return email;
    }

    @ManyToOne
    @JoinColumn(name="company_id")
    public Company getCompany() {
        return company;
    }

    @Column(name = "old_id")
    public Long getOldId() {
        return oldId;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public void setMovil(String movil) {
        this.movil = movil;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public void setCompany(Company company) {
        this.company = company;
    }

    public void setOldId(Long oldId) {
        this.oldId = oldId;
    }

    @Override
    public boolean equals(Object other) {
        if(other == this){
            return true;
        }
        if(!(other instanceof Contact)){
            return false;
        }
        Contact _i = (Contact)other;
        return id.equals(_i.id);
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }

    @Override
    public String toString() {
        return firstName != null ? firstName : "" + " " + lastName != null ? lastName : "";
    }
}
